﻿
namespace Com.JJ1369.Service.Service
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using Com.JJ1369.Service.Model;


    // Implements application logic using the BusinessWorkEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class DepartmentTypeService : LinqToEntitiesDomainService<BusinessWorkEntities>
    {

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'DepartmentType' query.
        [Query(IsDefault = true)]
        public IQueryable<DepartmentType> GetDepartmentTypeList()
        {
            return this.ObjectContext.DepartmentType;
        }

        protected override int Count<T>(IQueryable<T> query)
        {
            return query.Count();
        }

        public void InsertDepartmentType(DepartmentType departmentType)
        {
            if (departmentType.EntityState != EntityState.Detached)
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(departmentType, EntityState.Added);
            }
            else
            {
                this.ObjectContext.DepartmentType.AddObject(departmentType);
            }
        }

        public void UpdateDepartmentType(DepartmentType currentDepartmentType)
        {
            this.ObjectContext.DepartmentType.AttachAsModified(currentDepartmentType, this.ChangeSet.GetOriginal(currentDepartmentType));
        }

        public void DeleteDepartmentType(DepartmentType departmentType)
        {
            if (departmentType.EntityState != EntityState.Detached)
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(departmentType, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.DepartmentType.Attach(departmentType);
                this.ObjectContext.DepartmentType.DeleteObject(departmentType);
            }
        }
    }
}


